<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="线索资料详情"></uni-navbar></view>

		<!-- <view class="uploader-add" @click="onTts">
			<image v-if="!play" src="/static/img/icon_76.png" mode="widthFix"></image>
			<image src="/static/img/icon_77.gif" v-else mode="widthFix"></image>
		</view> -->

		<view class="form-box form-box-show">
			<u-form>
				<u-form-item class="form-item" label="标题">{{ infoDetail.title }}</u-form-item>
				<u-form-item class="form-item" label="提出人">{{ infoDetail.submitBy }}</u-form-item>
				<u-form-item class="form-item" label="身份证号">{{ infoDetail.idCard }}</u-form-item>
				<u-form-item class="form-item" label="电话">{{ infoDetail.phone }}</u-form-item>
				<u-form-item class="form-item" label="单位">{{ infoDetail.unit }}</u-form-item>
				<u-form-item class="form-item" label="邮箱">{{ infoDetail.email }}</u-form-item>
				<u-form-item class="form-item" label="正文" label-position="top">
					<view class="form-input"><uni-parse :content="infoDetail.content || ''"></uni-parse></view>
				</u-form-item>
			</u-form>
		</view>

		<view class="file-list" v-if="fileList.length > 0">
			<view>附件:</view>
			<view class="file-item" v-for="(item, index) in fileList" :key="index" @click="$showLine(item)">
				<view class="file-name clamp">{{ item.name }}</view>
				<view class="right-type">预览</view>
			</view>
		</view>

		<view class="form-box form-box-show">
			<u-form>
				<u-form-item class="form-item" label="信访查询码">{{ infoDetail.queryCode }}</u-form-item>
			</u-form>
		</view>

		<block v-if="infoDetail.nodeStatus == '1'">
			<view class="form-box form-box-show">
				<u-form>
					<u-form-item class="form-item" label="信访回复" label-position="top">
						<view class="form-input"><uni-parse :content="infoDetail.replyContent || ''"></uni-parse></view>
					</u-form-item>
				</u-form>
			</view>
		</block>
		<block v-if="infoDetail.nodeStatus == '0' && type == 'reply'">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="信访回复" label-position="top">
						<view class="inr-input"><u-input input-align="left" v-model="form.replyContent" type="textarea" placeholder="请输入回复内容" :clearable="false" :height="160" :maxlength="-1" /></view>
					</u-form-item>
				</u-form>
			</view>

			<view class="fiexd-btm"><u-button class="form-btn" type="error" @click="confirm">提交</u-button></view>
		</block>
	</view>
</template>

<script>
import uniParse from '@/components/uni-parse/parse.vue';
import { mapState } from 'vuex';
export default {
	components: {
		uniParse
	},
	data() {
		return {
			id: '',
			type: '',
			fileList: [],
			infoDetail: {},
			form: {
				replyContent: ''
			},
			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.id = option.id;
		this.type = option.type || '';
		this.loadData();
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.userId = this.userInfo.sysUser.id;
				this.clientCode = this.userInfo.sysUser.clientCode;
			} else {
				this.$logout();
			}
		},
		loadData() {
			this.$request('/wangshangxinfang/petition-letter/detail', {
				id: this.id,
				userId: this.userId
			}).then((res) => {
				this.infoDetail = res.data;
				this.fileList = res.data.fileList;
			});
		},
		confirm() {
			if (this.form.replyContent == '') {
				this.$msg('请输入回复内容');
				return false;
			}
			this.$request('/wangshangxinfang/petition-letter/reply', {
				id: this.id,
				replyContent: this.form.replyContent,
				isSms: '1',
				userId: this.userId
			}).then((res) => {
				this.$msg(res.msg);
				this.loadData();
			});
		},
		onTts() {
			let text = this.infoDetail.title;
			text += ',' + this.$parseTime(this.infoDetail.createTime, '{y}-{m}-{d}');
			text += ',' + this.$htmlRegx(this.infoDetail.content);
			this.$tts(text, this, 500);
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.form-box {
	.form-item {
		@include mp-flex;
	}

	.form-input {
		width: 100%;
		text-align: left;
	}

	.inr-input {
		display: block;
		padding: 0 30rpx;
		width: 100%;
		// border-radius: 44px;
		background-color: $u-bg-color;
	}
}

.fiexd-btm {
	position: static;
	border-top: 10rpx solid $u-border-color;
	padding: 30rpx;
}
</style>
